home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1111 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.1 KB  |  66 lines

  1. Path: fido.asd.sgi.com!austern
  2. From: abell@mindspring.com (Andrew Bell)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: methods for accessing attributes
  5. Date: 16 Apr 1996 13:13:49 PDT
  6. Organization: MindSpring Enterprises
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4kv5fb$m3i@mule2.mindspring.com>
  9. References: <4koq35$dcd@news.isc.rit.edu>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Tue, 16 Apr 1996 02:53:33 GMT
  12. X-Newsreader: Forte Agent .99.82
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMXP/fky4NqrwXLNJAQE3bQH+I/IPoGaI5ljXNDTWLw5OK53YnK5Ui5ve
  15.     tb7o1e9SDgT2NAY6J6lhYgHKT4CUeRRGlZ94FdlK4A3zcSCShL/xDw==
  16.     =EBcC
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. feb6399@osfmail.isc.rit.edu (Frank Barrus) wrote:
  20. >Or shall all old code of this sort be simply converted to use
  21. >access methods, and should directly accessible public 
  22. >instance variables be completely avoided?
  23.  
  24. As a general rule, directly addressable public data is to be avoided,
  25. for a variety of reasons.
  26.  
  27. >If that's the case, then I'd like to stick with some sort of 
  28. >standard naming convention...  but I've seen all kinds of different
  29. >variations...
  30.  
  31. Let me put in my two cents worth:
  32.  
  33. A verb in a member function name should indicate that the function is
  34. not const, and vice versa.  It is, after all, useful to know which
  35. you're working with at any given time.  Thus for property foo, which
  36. may or may not be an explicit member of class Bar, we have:
  37.  
  38. class Bar
  39. {
  40.     public:
  41.         int foo() const;
  42.         void setFoo(int);
  43.             or
  44.         void set_foo(int)
  45.     private:
  46.         int myFoo;
  47. };
  48.  
  49. I like the "my" prefix for non-static member variables, as you can
  50. see.
  51.  
  52. Note that underscores preceding a name are often reserved by the
  53. system.  While underscore followed by a lowercase letter is not
  54. reserved, it is probably better to avoid using it anyway.
  55.  
  56. Andrew Bell
  57. abell@mindspring.com
  58.  
  59. ---
  60. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  61.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  62.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  63.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  64.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  65. ]
  66.